package logic

import (
	"svvenus/util/uttype"
	"svvenus/znet/zpb"
)

func (player *Player) InitInfo() *zpb.PlayerInit {
	info := &zpb.PlayerInit{}
	info.InfoBase = player.InfoBase()
	info.InfoMisc = player.InfoMisc()
	info.InfoItems = player.ItemInfoList()
	info.InfoEquips = player.EquipInfoList()
	return info
}

func (player *Player) Info() *zpb.PlayerInfo {
	info := &zpb.PlayerInfo{}
	info.InfoBase = player.InfoBase()
	info.InfoMisc = player.InfoMisc()
	return info
}

func (player *Player) InfoBase() *zpb.PlayerInfoBase {
	info := &zpb.PlayerInfoBase{}
	info.Pid = player.Id.Hex()
	info.UserId = player.UserId
	info.Name = player.Name
	info.Gender = int32(player.Gender)
	info.Head = int32(player.Head)
	info.Moneys = make(map[int32]int64)
	for k, v := range player.Moneys {
		info.Moneys[uttype.StringToInt32(k)] = v
	}
	return info
}

func (player *Player) InfoMisc() *zpb.PlayerInfoMisc {
	info := &zpb.PlayerInfoMisc{}
	info.FlagInt = make(map[int32]int32)
	for k, v := range player.FlagInt {
		info.FlagInt[uttype.StringToInt32(k)] = v
	}
	info.FlagDailyInt = make(map[int32]int32)
	for k, v := range player.FlagDailyInt {
		info.FlagDailyInt[uttype.StringToInt32(k)] = v
	}

	player.InfoFlagRed(info)

	return info
}

func (player *Player) InfoFlagRed(info *zpb.PlayerInfoMisc) {
	info.FlagRed = make(map[int32]int32)
	{
		var count int32 = 0
		for _, v := range player.Mails {
			if !v.Read {
				count++
			}
		}
		info.FlagRed[int32(zpb.FlagRed_frMail)] = count
	}
}

func (player *Player) PushInfo() {
	rid := zpb.EPid_GcPlayerPushInfo

	rsp := player.Info()

	player.Send(rid, 0, rsp)
}
func (player *Player) PushInfoBase() {
	rid := zpb.EPid_GcPlayerPushInfoBase

	rsp := player.InfoBase()

	player.Send(rid, 0, rsp)
}

func (player *Player) PushInfoMisc() {
	rid := zpb.EPid_GcPlayerPushInfoMisc

	rsp := player.InfoMisc()

	player.Send(rid, 0, rsp)
}
